let http = require('http');
let querystring = require('querystring');

let server = http.createServer();

server.on('request', function(req, res) {
    let arr = [];
    console.log(req);
    req.on('data', function(chunk) {
        arr.push(chunk)
    })
    req.on('end', function() {
        let str = Buffer.concat(arr).toString();
        console.log(str);
        res.statusCode = 200;
        res.setHeader('servant', 'saber')
        res.end('saber');
    })
})

let port = 8080;

server.listen(port, function(){
    console.log(`server start ${port}`)
})

server.on('error', function(err) {
    if (err.errno === 'EADDRINUSE') {
        port++
        server.listen(port)
    }
})